package com.bsj.travel.device.web.controller;

import com.bsj.travel.def.common.DTO.web.productTopic.ProductTopicDTO;
import com.bsj.travel.def.common.DTO.web.productTopic.ProductTopicSearchDTO;
import com.bsj.travel.def.common.VO.ProductTopicVO;
import com.bsj.travel.def.global.JsonResult;
import com.bsj.travel.device.service.ProductTopicService;
import com.bsj.travel.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/***
 * @description ProductTopicController
 * @author LiJiaXin
 * @version 1.0.0
 * @time 2024/1/18 11:03
 **/
@RestController
@RequestMapping("productTopic")
public class ProductTopicController {

    @Autowired
    private ProductTopicService productTopicService;

    /**
     * 添加主题
     *
     * @param productTopicDTO
     * @return com.bsj.travel.def.global.JsonResult
     * @author ljx
     * @time 2024/1/19 11:02
     */
    @PostMapping("/add")
    @RequiresPermissions(value = "productTopic:operation:add")
    public JsonResult add(@Validated ProductTopicDTO productTopicDTO) {
        return productTopicService.addProductTopic(productTopicDTO);
    }

    /**
     * 删除主题
     *
     * @param topicId
     * @return com.bsj.travel.def.global.JsonResult
     * @author ljx
     * @time 2024/1/19 11:02
     */
    @PostMapping("/delete/{topicId}")
    @RequiresPermissions(value = "productTopic:operation:delete")
    public JsonResult delete(@PathVariable Long topicId) {
        return productTopicService.deleteProductTopic(topicId);
    }

    /**
     * 修改主题
     *
     * @param productTopicDTO
     * @return com.bsj.travel.def.global.JsonResult
     * @author ljx
     * @time 2024/1/19 11:03
     */
    @PostMapping("/update")
    @RequiresPermissions(value = "productTopic:operation:update")
    public JsonResult update(@Validated ProductTopicDTO productTopicDTO) {
        return productTopicService.updateProductTopic(productTopicDTO);
    }

    /**
     * 根据主题id获取主题信息
     *
     * @param topicId
     * @return com.bsj.travel.def.global.JsonResult<com.bsj.travel.def.common.VO.ProductTopicVO>
     * @author ljx
     * @time 2024/1/19 11:03
     */
    @GetMapping("/getById/{topicId}")
    @RequiresPermissions(value = "productTopic:info:getById")
    public JsonResult<ProductTopicVO> getById(@PathVariable("topicId") Long topicId) {
        ProductTopicVO productTopicVO = productTopicService.getProductTopicInfoById(topicId);
        return JsonResult.success(productTopicVO);
    }

    /**
     * 主题列表
     *
     * @param productTopicSearchDTO
     * @return com.bsj.travel.def.global.JsonResult<java.util.List < com.bsj.travel.def.common.VO.ProductTopicVO>>
     * @author ljx
     * @time 2024/1/19 11:05
     */
    @GetMapping("/list")
    @RequiresPermissions(value = "productTopic:info:list")
    public JsonResult<List<ProductTopicVO>> list(ProductTopicSearchDTO productTopicSearchDTO) {
        return JsonResult.success(productTopicService.listProductTopic(productTopicSearchDTO));
    }

}
